/* Copyright (c) 2004-2022 peigen.info. All rights reserved. */

package info.peigen.hotpot.common.core.enums;

import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * <b>(Symbol)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2019-05-29
 */
@Getter
@NoArgsConstructor
@AllArgsConstructor
public enum Number {
    /** 为了对抗 Alibaba Java Coding 而存在的注释 */
    Zero(0, "〇", "零", "N", "N"),
    One(1, "一", "壹", "ⅰ", "Ⅰ"),
    Two(2, "二", "贰", "ⅱ", "Ⅱ"),
    Three(3, "三", "叁", "ⅲ", "Ⅲ"),
    Four(4, "四", "肆", "ⅳ", "Ⅳ"),
    Five(5, "五", "伍", "ⅴ", "Ⅴ"),
    Six(6, "六", "陆", "ⅵ", "Ⅵ"),
    Seven(7, "七", "柒", "ⅶ", "Ⅶ"),
    Eight(8, "八", "捌", "ⅷ", "Ⅷ"),
    Nine(9, "九", "玖", "ⅸ", "Ⅸ"),
    ;

    /** 阿拉伯數字 */
    private Integer number;

    /** 中文小写 */
    private String chineseLowercase;

    /** 中文大写 */
    private String chineseCapital;

    /** 罗马小写 */
    private String romanLowercase;

    /** 罗马大写 */
    private String romanCapital;

    /**
     * 通过枚举<number>number</number>获得枚举
     *
     * @param number number
     *
     * @return Number
     */

    public static Number getByNumber(Integer number) {
        return Stream.of(values())
                .filter(innerEnum -> number.equals(innerEnum.number()))
                .findFirst().orElse(null);
    }

    /**
     * 通过枚举<number>chineseLowercase</number>获得枚举
     *
     * @param chineseLowercase String
     *
     * @return Number
     */
    public static Number getByChineseLowercase(String chineseLowercase) {
        return Stream.of(values())
                .filter(innerEnum -> StrUtil.equals(chineseLowercase, innerEnum.chineseLowercase()))
                .findFirst().orElse(null);
    }

    /**
     * 通过枚举<number>chineseCapital</number>获得枚举
     *
     * @param chineseCapital String
     *
     * @return Number
     */
    public static Number getByChineseCapital(String chineseCapital) {
        return Stream.of(values())
                .filter(innerEnum -> StrUtil.equals(chineseCapital, innerEnum.chineseLowercase()))
                .findFirst().orElse(null);
    }

    /**
     * 通过枚举<number>romanLowercase</number>获得枚举
     *
     * @param romanLowercase String
     *
     * @return Number
     */
    public static Number getByRomanLowercase(String romanLowercase) {
        return Stream.of(values())
                .filter(innerEnum -> StrUtil.equals(romanLowercase, innerEnum.chineseLowercase()))
                .findFirst().orElse(null);
    }

    /**
     * 通过枚举<number>romanCapital</number>获得枚举
     *
     * @param romanCapital String
     *
     * @return Number
     */
    public static Number getByRomanCapital(String romanCapital) {
        return Stream.of(values())
                .filter(innerEnum -> StrUtil.equals(romanCapital, innerEnum.chineseLowercase()))
                .findFirst().orElse(null);
    }

    /**
     * 获取全部枚举
     *
     * @return List<Number>
     */
    public static List<Number> getAllEnum() {
        return Lists.newArrayList(values());
    }

    /**
     * 获取全部阿拉伯數字
     *
     * @return List<Integer>
     */
    public static List<Integer> getAllNumber() {
        return getAllEnum().stream().map(innerEnum -> innerEnum.number()).collect(Collectors.toList());
    }

    /**
     * 获取全部中文小写
     *
     * @return List<String>
     */
    public static List<String> getAllChineseLowercase() {
        return getAllEnum().stream().map(innerEnum -> innerEnum.chineseLowercase()).collect(Collectors.toList());
    }

    /**
     * 获取全部中文大写
     *
     * @return List<String>
     */
    public static List<String> getAllChineseCapital() {
        return getAllEnum().stream().map(innerEnum -> innerEnum.chineseCapital()).collect(Collectors.toList());
    }

    /**
     * 获取全部罗马数字小写
     *
     * @return List<String>
     */
    public static List<String> getAllRomanLowercase() {
        return getAllEnum().stream().map(innerEnum -> innerEnum.romanLowercase()).collect(Collectors.toList());
    }

    /**
     * 获取全部罗马数字大写
     *
     * @return List<String>
     */
    public static List<String> getAllRomanCapital() {
        return getAllEnum().stream().map(innerEnum -> innerEnum.romanCapital()).collect(Collectors.toList());
    }

    /**
     * 获取枚举code
     *
     * @param innerEnum enum
     *
     * @return Integer
     */
    public static Integer getNumber(Number innerEnum) {
        return Optional.ofNullable(innerEnum).map(inner -> inner.getNumber()).orElse(null);
    }

    /**
     * map
     *
     * @return Map
     */
    public static Map<Integer, String> lowercaseMaps() {
        return Stream.of(values()).collect(Collectors.toMap(Number::number, Number::chineseLowercase));
    }

    /**
     * map
     *
     * @return Map
     */
    public static Map<Integer, String> capitalMaps() {
        return Stream.of(values()).collect(Collectors.toMap(Number::number, Number::chineseCapital));
    }

    public Integer getNumber() {
        return number;
    }

    public String getChineseLowercase() {
        return chineseLowercase;
    }

    public String getChineseCapital() {
        return chineseCapital;
    }

    public String getRomanLowercase() {
        return romanLowercase;
    }

    public String getRomanCapital() {
        return romanCapital;
    }

    public Integer number() {
        return number;
    }

    public String chineseLowercase() {
        return chineseLowercase;
    }

    public String chineseCapital() {
        return chineseCapital;
    }

    public String romanLowercase() {
        return romanLowercase;
    }

    public String romanCapital() {
        return romanCapital;
    }
}